/*
* =====================================================================================
*
*       Filename:  ofprint_client.c
*
*    Description:
*
*        Version:  1.0
*        Created:  02/15/2023 15:50:00 PM
*       Revision:  none
*       Compiler:  gcc
*
*         Author:  huciqing
*   Organization:  ofilm oms
*
* =====================================================================================
*/
#include <glib.h>
#include <gio/gio.h>
#include <unistd.h>
#include "ofprint-generated.h"
#include "ofprint-client.h"


static gboolean test_status_handler(Ofprint* object, char *id, gint code, char *msg, gpointer user_data)
{
	g_print("signal received code %d\n", code);
	return TRUE;
}

#if 0
static void cb_OwnerNameChangedNotify(GObject *object, GParamSpec *pspec, gpointer userdata)
{
	gchar *pname_owner = NULL;
	pname_owner = g_dbus_proxy_get_name_owner((GDBusProxy*)object);
	 
	if (NULL != pname_owner){
		g_print("DBus service is ready!\n");
		g_free(pname_owner);
	}
	else{
		g_print("DBus service is NOT ready!\n");
		g_free(pname_owner);
	}
}
#endif

int main(int argc, char *argv[])
{
	Ofprint *proxy=NULL;
	GError *error = NULL;
	GMainLoop* loop = NULL;
	 
	proxy = ofprint_proxy_new_for_bus_sync (
		G_BUS_TYPE_SYSTEM,//SESSION
		G_DBUS_PROXY_FLAGS_NONE,
		"ofilm.oms.Ofprint",
		"/ofilm/oms/Ofprint",
		NULL,
		&error);
	 
	if(0 == proxy)
	{
		g_print("InitDBusCommunication: Failed to create proxy. Reason: %s.\n", error->message);
	}


	g_signal_connect(proxy,"enroll-status",G_CALLBACK(test_status_handler),NULL);
#if 1	 
	char *reply = NULL;
	ofprint_call_stop_enroll_sync (proxy, NULL, &error);
	g_print("sync reply = %s\n",reply);
#endif	 
	loop = g_main_loop_new(NULL, FALSE);
	g_main_loop_run(loop);
	 
	g_object_unref(proxy);
	return 0;
}

